package com.frcdi.qms.web.controller.measurement;

import com.frcdi.qms.common.core.controller.BaseController;
import com.frcdi.qms.common.core.domain.AjaxResult;
import com.frcdi.qms.common.core.page.TableDataInfo;
import com.frcdi.qms.common.utils.poi.ExcelUtil;
import com.frcdi.qms.measurement.domain.MeasurementRecord;
import com.frcdi.qms.measurement.service.IMeasurementRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 一般性测量数据采集记录Controller
 *
 * @author cell
 * @date 2024-02-27
 */
@Api(tags = "一般性测量数据采集记录")
@RestController
@RequestMapping("/measurement/record")
public class MeasurementRecordController extends BaseController
{
    @Autowired
    private IMeasurementRecordService measurementRecordService;

    /**
     * 查询一般性测量数据采集记录列表
     */
    @ApiOperation("查询一般性测量数据采集记录列表")
    @PreAuthorize("@ss.hasPermi('measurement:record')")
    @GetMapping("/list")
    public TableDataInfo list(MeasurementRecord measurementRecord)
    {
        startPage();
        List<MeasurementRecord> list = measurementRecordService.selectMeasurementRecordList(measurementRecord);
        return getDataTable(list);
    }

    /**
     * 导出一般性测量数据采集记录列表
     */
    @ApiOperation("导出一般性测量数据采集记录列表")
    @PreAuthorize("@ss.hasPermi('measurement:record')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeasurementRecord measurementRecord)
    {
        List<MeasurementRecord> list = measurementRecordService.selectMeasurementRecordList(measurementRecord);
        ExcelUtil<MeasurementRecord> util = new ExcelUtil<MeasurementRecord>(MeasurementRecord.class);
        util.exportExcel(response, list, "一般性测量数据采集记录数据");
    }

    /**
     * 获取一般性测量数据采集记录详细信息
     */
    @ApiOperation("获取一般性测量数据采集记录详细信息")
    @PreAuthorize("@ss.hasPermi('measurement:record')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(measurementRecordService.selectMeasurementRecordByRecordId(recordId));
    }

    /**
     * 新增一般性测量数据采集记录
     */
    @ApiOperation("新增一般性测量数据采集记录")
    @PreAuthorize("@ss.hasPermi('measurement:record')")
    @PostMapping
    public AjaxResult add(@RequestBody MeasurementRecord measurementRecord)
    {
        measurementRecord.setCreateBy(getUsername());
        return toAjax(measurementRecordService.insertMeasurementRecord(measurementRecord));
    }

    /**
     * 修改一般性测量数据采集记录
     */
    @ApiOperation("修改一般性测量数据采集记录")
    @PreAuthorize("@ss.hasPermi('measurement:record')")
    @PutMapping
    public AjaxResult edit(@RequestBody MeasurementRecord measurementRecord)
    {
        measurementRecord.setUpdateBy(getUsername());
        return toAjax(measurementRecordService.updateMeasurementRecord(measurementRecord));
    }

    /**
     * 删除一般性测量数据采集记录
     */
    @ApiOperation("删除一般性测量数据采集记录")
    @PreAuthorize("@ss.hasPermi('measurement:record')")
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(measurementRecordService.deleteMeasurementRecordByRecordIds(recordIds));
    }

    @ApiOperation("重新测量一般性测量数据采集记录")
    @PreAuthorize("@ss.hasPermi('measurement:record')")
    @PostMapping("reMeasure")
    public AjaxResult reMeasure(@RequestBody MeasurementRecord measurementRecord)
    {
        return toAjax(measurementRecordService.reMeasure(measurementRecord));
    }
}
